home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / winterp-1.13 / src-server / utils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-04  |  3.8 KB  |  98 lines

  1. /* -*-C-*-
  2. ********************************************************************************
  3. *
  4. * File:         utils.c
  5. * RCS:          $Header: utils.c,v 1.2 91/03/14 03:13:20 mayer Exp $
  6. * Description:  random, non-X utility functions needed by WINTERP
  7. * Author:       Niels Mayer, HPLabs
  8. * Created:      Thu Oct 25 22:37:08 1990
  9. * Modified:     Thu Oct  3 20:01:34 1991 (Niels Mayer) mayer@hplnpm
  10. * Language:     C
  11. * Package:      N/A
  12. * Status:       X11r5 contrib tape release
  13. *
  14. * WINTERP Copyright 1989, 1990, 1991 Hewlett-Packard Company (by Niels Mayer).
  15. * XLISP version 2.1, Copyright (c) 1989, by David Betz.
  16. *
  17. * Permission to use, copy, modify, distribute, and sell this software and its
  18. * documentation for any purpose is hereby granted without fee, provided that
  19. * the above copyright notice appear in all copies and that both that
  20. * copyright notice and this permission notice appear in supporting
  21. * documentation, and that the name of Hewlett-Packard and David Betz not be
  22. * used in advertising or publicity pertaining to distribution of the software
  23. * without specific, written prior permission.  Hewlett-Packard and David Betz
  24. * make no representations about the suitability of this software for any
  25. * purpose. It is provided "as is" without express or implied warranty.
  26. *
  27. * HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  28. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  29. * IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  30. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  31. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  32. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  33. * PERFORMANCE OF THIS SOFTWARE.
  34. *
  35. * See ./winterp/COPYRIGHT for information on contacting the authors.
  36. * Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  37. * Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  38. *
  39. ********************************************************************************
  40. */
  41. static char rcs_identity[] = "@(#)$Header: utils.c,v 1.2 91/03/14 03:13:20 mayer Exp $";
  42.  
  43.  
  44. /*
  45.  * I don't have time to figure out how to make sleepms() portable. sleepms()
  46.  * is used by w_utils.c:Wut_Prim_X_REFRESH_DISPLAY(), which is a hack
  47.  * bug workaround for some Motif/Xt/X anomalies.
  48.  *
  49.  * If you want to try to get this working on your non-HPUX system, feel free
  50.  * to show me how. A few hints: use <X11/Xos.h> rather than <time.h>
  51.  * change sigvector() to sigvec(), etc. I tried that, but ran into a bunch
  52.  * of weird compiler errors. So I punted....
  53.  */
  54. #ifdef hpux
  55.  
  56. #include <stdio.h>
  57. #include <signal.h>
  58. #include <time.h>
  59.  
  60. static void alarmhandler()
  61. {
  62. }
  63.  
  64. /******************************************************************************
  65.  * sleepms -- this procedure sleeps for <msec> milliseconds. It is similar to
  66.  * sleep(3C).
  67.  *
  68.  * This procedure was stolen from some code written by 
  69.  * Nathan Meyers, HP Interface Technology Operation
  70. ******************************************************************************/
  71. sleepms(msec)
  72.      int msec;
  73. {
  74.   struct itimerval value, ovalue;
  75.   struct sigvec vec, ovec;
  76.   long savemask, sigblock(), sigpause(), sigsetmask();
  77.  
  78.   vec.sv_handler = alarmhandler;
  79.   vec.sv_mask = 0x0;
  80.   vec.sv_flags = 0;
  81.   sigvector(SIGALRM, &vec, &ovec); /* Set up alarmhandler for SIGALRM */
  82.   savemask = sigblock((long)(1L << (SIGALRM - 1)));
  83.  
  84.   value.it_interval.tv_sec = 0;
  85.   value.it_interval.tv_usec = 0;
  86.   value.it_value.tv_sec = msec / 1000;
  87.   value.it_value.tv_usec = (msec % 1000) * 1000;
  88.   setitimer(ITIMER_REAL, &value, &ovalue);
  89.  
  90.   (void)sigpause(~(long)(1L << (SIGALRM - 1)));
  91.   (void)sigsetmask(savemask);
  92.  
  93.   sigvector(SIGALRM, &ovec, NULL);    /* Restore previous signal handler */
  94. }
  95.  
  96. #endif                /* hpux */
  97.